package com.wmyg.antifake.gs1.ns2.converters;

import com.wmyg.antifake.gs1.ns2.SpecialString;
import com.wmyg.antifake.gs1.ns2.basic.PackagingSignatureLine;
import com.wmyg.antifake.gs1.ns2.basic.StringAVP;
import org.dom4j.Element;

import java.util.List;

/**
 * @program: antifake
 * @description: 包装信息转换器
 * @author: wong
 * @create: 19-4-23
 */
public class PackagingSignatureLineConverter {

    protected static PackagingSignatureLine convert(Element element) {
        PackagingSignatureLine p = new PackagingSignatureLine();
        List<Element> children = element.elements();
        for (Element e :
                children) {
            switch (e.getName()) {
                case "partyContactRoleCode":
                    p.setPartyContactRoleCode(new SpecialString(e));
                    break;
                case "partyContactName":
                    p.setPartyContactName(e.getText());
                    break;
                case "partyContactAddress":
                    p.setPartyContactAddress(e.getText());
                    break;
                case "avpList":
                    List<Element> avps = e.elements();
                    for (Element avp :
                            avps) {
                        p.getAvpList().add(new StringAVP(avp));
                    }
                    break;
                default:
            }
        }
        return p;
    }

}
